package com.jojo.android.zxlib.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.jojo.android.zxlib.R;

/**
 * 创建者 zx
 * 创建时间 2020/8/15 20:48
 */
public class PopupWindowUtil {


    public static PopupWindow CreatePopupWindow(final Activity activity, View view, int w, int h) {
        PopupWindow popupWindow = new PopupWindow(view, w, h);
        // 设置背景
        popupWindow.setBackgroundDrawable(new ColorDrawable(0));
        // 外部点击事件
        popupWindow.setOutsideTouchable(true);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams params = activity.getWindow().getAttributes();
                params.alpha = 1f;
                activity.getWindow().setAttributes(params);
            }
        });

        WindowManager.LayoutParams params = activity.getWindow().getAttributes();
        params.alpha = 0.4f;
        activity.getWindow().setAttributes(params);
        popupWindow.setAnimationStyle(R.style.popup_anim);
        return popupWindow;
    }

    public static PopupWindow CreatePopupWindow(final Activity activity, View view) {
        return CreatePopupWindow(activity, view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }


}
